package JdkProxy;

import java.lang.reflect.InvocationHandler;
import java.lang.reflect.Method;
import java.lang.reflect.Proxy;

public class LogProxy implements InvocationHandler {
    private UserService userService;

    public LogProxy(UserService target){
        this.userService = target;
    }

    public  Object getTarget(){
        return Proxy.newProxyInstance(userService.getClass().getClassLoader(),userService.getClass().getInterfaces(),this);
    }

    public Object invoke(Object proxy, Method method, Object[] args) throws Throwable {
        System.out.println("log.....");
        UserService u = (UserService) method.invoke(userService,args);
        return u;
    }
}
